# An individual person
class Person < ActiveRecord::Base
  belongs_to :company
  belongs_to :address

  EMAIL_REGEX = /^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i
  validates_format_of :email, :with => EMAIL_REGEX, :message => "Please supply a valid email address"  
  validates_uniqueness_of :email, :message => "This email address already exists"
  
  validates_presence_of :first_name, :message => 'Please enter a first name'
  validates_presence_of :last_name, :message => 'Please enter a last name'

  GENDERS = {'M' => 'male', 'F' => 'female'}
  validates_inclusion_of :gender, :in => GENDERS.keys,
  :message => "Please select 'M' or 'F' for the genre"

  def full_gender
    GENDERS[gender]
  end
  
  def self.find_all_ordered
    find :all, :order => 'last_name, first_name'
  end
end
